var width = document.body.clientWidth; //可见区域宽度
var swiper = new Swiper('.swiper',{
    effect: 'coverflow',
    grabCursor: true,
    centeredSlides: true,
    slidesPerView: 'auto',
    initialSlide: 0,
    coverflow: {
        rotate: 0,
        stretch: width*30/100,
        depth: 300,
        modifier: 1,
        slideShadows : false
    } 
})
function isH(direction) { //判断可滑动slider是否为垂直方向
    return direction === 'horizontal';
}
var setTranslate = swiper.effects.coverflow.setTranslate
swiper.effects.coverflow.setTranslate = function() {
    setTranslate()

    var s = swiper;
    var transform = s.translate;
    var center = isH(s.params.direction) ? -transform + s.width / 2 : -transform + s.height / 2;
    // var rotate = isH(s.params.direction) ? s.params.coverflow.rotate: -s.params.coverflow.rotate;
    // var translate = s.params.coverflow.depth;  

    //Each slide offset from center
    for (var i = 0, length = s.slides.length; i < length; i++) {
        var opacity = 1;
        var slide = s.slides.eq(i);
        var slideSize = s.slidesSizesGrid[i];
        var slideOffset = slide[0].swiperSlideOffset;
        var offsetMultiplier = (center - slideOffset - slideSize / 2) / slideSize * s.params.coverflow.modifier;

        //设置slider的透明度
        if(offsetMultiplier >= 0 && offsetMultiplier < 1) {
            opacity = 1 - offsetMultiplier; //滑动中中间轴右边第一个透明度由1变为0
        } else if(offsetMultiplier >= 1) {
            opacity = 0; //滑动中中间轴右边除了第一个其他透明度为零
        } else {
            opacity = 1; //滑动中中间轴左边的透明度全为1
        } 
        slide.css("opacity", opacity);

        console.log('slide index', i)
        var slideTransform = slide.css('transform');
        console.log('slideTransform', slideTransform)
        var translateNum = s.getTranslate(slide[0], 'x')
        console.log('translateNum', translateNum)
    }
}
